<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ taglib uri="/struts-json-tags" prefix="json" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>json</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<script type="text/javascript">
   var XHR=false;/*定义xmlhttprequest变量*/
   function CreateXHR(){
   try{
	   /*检查能否用ActiveXObject*/
   XHR=new ActiveXObject("msxm12.XMLHTTP");
   }catch(e1){
      try{
    	  /*检查能否用ActiveXObject*/
      XHR=new XMLHttpRequest("microsoft.XMLHTTP");
      }catch(e2){
            try{
            	/*检查能否用本地javascript*/
                 XHR=new XMLHttpRequest();
            }catch(e3){
                 XHR=false;//创建失败
            }
      }
   }
   }
   
   function sendRequest(uri){
	  
          CreateXHR();//创建xmlhttprequest对象
          if(XHR){
             XHR.open("GET",uri,false);//创建成功访问open
             XHR.onreadystatechange=resultHander;//设置事件触发
             XHR.send(null);//发送请求
          }
   }
   
   function resultHander(){
        if(XHR.readyState==4&&XHR.status==200){
           var userObj=JSON.parse(XHR.responseText);//得到jison对象
           var userStr="<table border=0>";
           userStr+=('<tr><td><b>Name</b></td><td>'+userObj.USER.name+'</td></tr>');
           userStr+=('<tr><td><b>Name</b></td><td>'+userObj.USER.age+'</td></tr>');
           userStr+="</table>";
           document.getElementById('jsonDiv').innerHTML=userStr;//插入对象值
        }
   }
</script>
  </head>
  
  <body>
    <center>
       <div id="jsonDiv"></div>
       <input type="button" value="OK" onclick="sendRequest('userJson')"/>
    </center>
  </body>
</html>
